package com.tlias.tliaswebmanagement.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    /**
     * 响应码：1 成功，0 代表失败
     */
    private Integer code;
    private String msg;
    private T data;

    /**
     * 返回默认的成功结果
     */
    public static <T> Result<T> success() {
        return new Result<>(1, "操作成功", null);
    }

    /**
     * 返回成功结果，并携带响应数据
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(1, "操作成功", data);
    }

    /**
     * 返回默认的失败结果
     */
    public static <T> Result<T> fail(String msg) {
        return new Result<>(0, msg, null);
    }
}